Getting Started with SAS Programming by Ron Cody

Getting Started with SAS Programming by Ron Cody

Author:Ron Cody [Ron Cody]
Language: eng
Format: epub, pdf
Publisher: SAS Institute
Published: 2021-02-24T00:00:00+00:00


The program worked as advertised.

Extracting the Day of the Week, Day of the Month, Month, and Year from a SAS Date

You can use the four functions, WEEKDAY, DAY, MONTH and YEAR, to compute the day of the week (a number from 1 to 7, with 1=Sunday), day of the month (a number from 1 to 31), month of the year (a number from 1 to 12), and year from a SAS date. Let’s look at an example.

You have a SAS data set with a variable called Date. You would like to generate bar charts showing frequencies for day of the week, day of the month, and year.

To save room, this program only produces a bar chart for the day of the week. You can substitute the day of the month or year to obtain bar charts for these variables. The DATA step that creates the data set containing the Date variable is included so that you can try running the program yourself.

Program 13.4: Extracting the Day of the Week, Day of the Month, and Year from a SAS Date

data Extract;

informat Date mmddyy10.;

input Date @@; 

Day_of_Week = weekday(Date); 

Day_of_Month = day(Date);

Year = year(Date);

format Date mmddyyd10.;

datalines;

1/5/2000 2/8/2000 4/23/2000 4/12/2000 8/21/2000 8/21/2000 8/22/2000

12/12/2000 12/15/2000 12/18/2000

2/22/2001 2/1/2001 4/18/2001 4/18/2001 4/18/2001 9/17/2001 12/25/2001

12/22/2001 3/3/2001 3/6/2001 3/7/2001

;

title “Listing of the First Eight Observations from Extract”;

proc print data=Extract (obs=8); 

run;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.